function getSite() {
	return new Promise(resolve => {
		wx.getLocation({
			type: 'gcj02',
			success: res => {
				// this.classInfo.lat = res.latitude;
				// this.classInfo.lng = res.longitude;
				resolve(res);
			},
			fail: () => {
				uni.showToast({
					title: '获取位置信息失败',
					icon: 'none'
				});
				resolve();
			}
		});
	});
}

function getLocation() {
	return new Promise(resolve => {
		wx.getSetting({
			success: res => {
				let _status = res.authSetting['scope.userLocation'];
				if (_status) {
					// 已授权
					getSite().then(res => {
						resolve(res);
					});
				} else if (_status == undefined) {
					// 第一次进入
					getSite().then(res => {
						resolve(res);
					});
				} else {
					// 拒绝授权位置信息
					uni.showModal({
						title: '提示',
						content: '需要提供您的位置信息才能正常使用点名功能,点击确认跳转到设置页面授权',
						success: res => {
							if (res.confirm) {
								wx.openSetting({
									success: res => {
										if (res.authSetting['scope.userLocation']) {
											getSite().then(res => {
												resolve(res);
											});
										} else {
											resolve();
										}
									}
								});
							} else {
								resolve();
							}
						}
					});
				}
			}
		});
	});
}

export default getLocation;
